import {expect} from "chai";
import { Vec2 } from "../src/Vec2";
import { Mat2 } from "../src/Mat2";
import { Mat3 } from "../src/Mat3";
import { Mat4 } from "../src/Mat4";
describe("Vec2", function () {
    before(function() {
        console.log("开始自动化测试Vec2...");
    });

    after(function() {
        console.log("结束...");
    });
    beforeEach(function() {
    });

    afterEach(function() {
    });

    it('#constructor', function () {
        let vec2=new Vec2();
        expect(vec2.equal([0,0])).to.equal(true);
    });
    it('#x', function () {
        let vec2=new Vec2([2,3]);
        expect(vec2.x).to.equal(2);
    });
    it('#y', function () {
        let vec2=new Vec2([2,3]);
        expect(vec2.y).to.equal(3);
    });
    it('#toString', function () {
        let vec2=new Vec2([3,4]);
        expect(vec2.toString()).to.equal("Vec2(3,4)");
    });
    it('#copy', function () {
        let vec2=new Vec2([3,4]);
        let vec21=new Vec2([5,4]);
        vec2.copy(vec21)
        expect(vec2.toString()).to.equal("Vec2(5,4)");
    });
    it('#equal', function () {
        let vec2=new Vec2([3,4]);
        let vec21=vec2.clone();
        expect(vec21.equal(vec2)).to.equal(true);
    });
    it('#clone', function () {
        let vec2=new Vec2([3,4]);
        let vec21=vec2.clone();
        expect(vec21.equal(vec2)).to.equal(true);
    });
    it('#add', function () {
        let vec2=new Vec2([3,4]);
        vec2.add([3,4])
        expect(vec2.toString()).to.equal("Vec2(6,8)");
    });
    it('#sub', function () {
        let vec2=new Vec2([3,4]);
        vec2.sub([3,4])
        expect(vec2.toString()).to.equal("Vec2(0,0)");
    });
    it('#multiply', function () {
        let vec2=new Vec2([3,4]);
        vec2.multiply([3,4])
        expect(vec2.toString()).to.equal("Vec2(9,16)");
    });
    it('#div', function () {
        let vec2=new Vec2([3,4]);
        vec2.div([3,4])
        expect(vec2.toString()).to.equal("Vec2(1,1)");
    });
    it('#scale', function () {
        let vec2=new Vec2([3,4]);
        vec2.scale(2)
        expect(vec2.toString()).to.equal("Vec2(6,8)");
    });
    it('#negate', function () {
        let vec2=new Vec2([3,4]);
        vec2.negate();
        expect(vec2.toString()).to.equal("Vec2(-3,-4)");
    });
    it('#length', function () {
        let vec2=new Vec2([3,4]);
        expect(vec2.length()).to.equal(5);
    });
    it('#distance', function () {
        let vec2=new Vec2([3,4]);
        expect(vec2.distance([0,0])).to.equal(5);
    });
    it('#lerp', function () {
        let vec2=new Vec2([0,1]);
        vec2.lerp(0.5);
        expect(vec2.toString()).to.equal("Vec2(0,0.5)");
    });
    it('#rotate', function () {
        let vec2=new Vec2([1,1]);
        vec2.rotate(Math.PI/4);
        expect(vec2.equal([0,1.414213562373095])).to.equal(true);
    });
    it('#angle', function () {
        let vec2=new Vec2([1,1]);
        let angle=vec2.angle([1,0]).toFixed(15);
        expect(angle).to.be.equal('0.785398163397448');
    });
    it('#inverse', function () {
        let vec2=new Vec2([2,2]);
        vec2.inverse();
        expect(vec2.toString()).to.equal("Vec2(0.5,0.5)");
    });
    it('#abs', function () {
        let vec2=new Vec2([-2,2]);
        vec2.abs();
        expect(vec2.toString()).to.equal("Vec2(2,2)");
    });
    it('#dot', function () {
        let vec2=new Vec2([1,1]);
        expect(vec2.dot([1,0])).to.equal(1);
    });
    it('#cross', function () {
        let vec1=new Vec2([3,2]);
        let vec2=new Vec2([1,2]);
        let out=vec1.cross(vec2)
        expect(out.equal([0,0,4])).to.equal(true);
    });
    it('#transformMat2', function () {
        let vec2=new Vec2([2,2]);
        let mat2=new Mat2().fromScaling([0.5,0.5]);
        vec2.transformMat2(mat2);        
        expect(vec2.equal(new Vec2([1,1]))).to.equal(true);
    });
    it('#transformMat3', function () {
        let vec2=new Vec2([2,2]);
        let mat3=new Mat3().fromScaling([0.5,0.5]);
        vec2.transformMat3(mat3);        
        expect(vec2.equal(new Vec2([1,1]))).to.equal(true);
    });
    it('#transformMat4', function () {
        let vec2=new Vec2([2,2]);
        let mat4=new Mat4().fromScaling([0.5,0.5]);
        vec2.transformMat4(mat4);        
        expect(vec2.equal(new Vec2([1,1]))).to.equal(true);
    });
    it('#normalize', function () {
        let vec2=new Vec2([2,2]);
        vec2.normalize();
        expect(vec2[0]).to.equal(1/Math.sqrt(2));
    });
    
})